package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/1/22 10:05
 * @apiNote
 */

public class Test00345ReverseVowels {

    public static String reverseVowels(String s) {
        int i = 0,j= s.length() - 1;
        char[] arr= s.toCharArray();
        while(i<j){
            while(i<j && !isVowel(arr[i])){
                i++;
            }
            while(i<j && !isVowel(arr[j])){
                j--;
            }
            if(i<j){
                char temp = arr[i];
                arr[i]= arr[j];
                arr[j] = temp;
                i++;
                j--;
            }
        }
        return new String(arr);
    }

    public static boolean isVowel(char ch) {
        return "aeiouAEIOU".indexOf(ch) >= 0;
    }

}
